﻿<%@ Page Language="C#" MasterPageFile="~/Theme/Stander/Stander.master" AutoEventWireup="true" 
    CodeFile="FinanceStatistics.aspx.cs" Inherits="Finance_FinanceStatistics" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script language="javascript" type="text/javascript">
$(function() {
    var agent = $('#<%= txtAgentName.ClientID %>');
    var customer = $('#<%= txtCustomerName.ClientID %>');
    var media = $('#<%= txtMediaName.ClientID %>');
    var validator = $get('<%= rfvInputValue.ClientID %>');
    $('#<%= ddlSearchType.ClientID %>').change(function() {
        agent.hide();
        customer.hide();
        media.hide();
        switch($(this).val()) {
            case "Agent":
                agent.show().val("");
                validator.controltovalidate = agent.attr("id");
                break;
            case "Customer":
                customer.show().val("");
                validator.controltovalidate = customer.attr("id");
                break;
            default:
                media.show().val("");
                validator.controltovalidate = media.attr("id");
                break;
        }
    });
});
</script>

<h2>统计</h2>
<div class="form">
<ul>
    <li>
        <span class="name">查询对象:</span>
        <span class="value">
        <asp:DropDownList ID="ddlSearchType" runat="server">
            <asp:ListItem Text="代理" Value="Agent"></asp:ListItem>
            <asp:ListItem Text="客户" Value="Customer"></asp:ListItem>
            <asp:ListItem Text="媒介" Value="Media"></asp:ListItem>
        </asp:DropDownList>
        </span>
    </li>
    <li>
        <span class="name">名称:</span>
        <span class="value">
            <asp:TextBox id="txtAgentName" runat="server"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="aceAgentName" 
                 TargetControlID="txtAgentName" ServiceMethod="GetAgentNamesList"
                 ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
                 CompletionInterval="500" EnableCaching="true" Enabled="true"
                 CompletionSetCount="10"/>
            <asp:TextBox id="txtCustomerName" runat="server" style="display: none;"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="aceCustomerName"
                 TargetControlID="txtCustomerName" ServiceMethod="GetCustomerNamesList"
                 ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
                 CompletionInterval="500" EnableCaching="true" Enabled="true"
                 CompletionSetCount="10"/>
            <asp:TextBox id="txtMediaName" runat="server" style="display: none;"></asp:TextBox> 
            <ajaxToolkit:AutoCompleteExtender runat="server" ID="aceMediaName" 
                         TargetControlID="txtMediaName" ServiceMethod="GetMediaNamesList"
                         ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
                         CompletionInterval="500" EnableCaching="true" Enabled="true"
                         CompletionSetCount="10"/>   
            <asp:RequiredFieldValidator ID="rfvInputValue" ControlToValidate="txtAgentName"
                Display="Dynamic" runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
            
        </span>
    </li>
    <li>
        <span class="name">时间范围:</span>
        <span class="value">
            <asp:TextBox ID="txtStartDate" runat="server" CssClass="date"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ErrorMessage="*" ControlToValidate="txtStartDate"></asp:RequiredFieldValidator> 至
            <asp:TextBox ID="txtEndDate" runat="server" CssClass="date"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                ErrorMessage="*" ControlToValidate="txtEndDate"></asp:RequiredFieldValidator>
            <ajaxToolkit:CalendarExtender id="txtStartDateCalendarExtender" runat="server" 
                TargetControlID="txtStartDate" Format="yyyy-M-d">
            </ajaxToolkit:CalendarExtender>
            <ajaxToolkit:CalendarExtender id="txtEndDateCalendarExtender" runat="server" 
                TargetControlID="txtEndDate" Format="yyyy-M-d">
            </ajaxToolkit:CalendarExtender>
        </span>
    </li>
    <li>
        <span class="name"></span>
        <span class="value">
        <asp:Button ID="btnCalculate" runat="server" Text="计算" OnClick="btnCalculate_Click" />
        </span>
    </li>
</ul>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnCalculate" />
</Triggers>
<ContentTemplate>
<asp:Label ID="lblError" CssClass="error" runat="server" Text=""></asp:Label>
<asp:Panel ID="plResult" runat="server" Visible="false">
<h2>统计信息</h2>
<table class="normal">
    <tr>
        <th>交易次数</th>
        <th>应收款</th>
        <th>实际收款</th>
        <th>应付款</th>
        <th>实际付款</th>
        <th>应得利润</th>
        <th>实际利润</th>
    </tr>
    <tr>
        <td>
            <asp:Label ID="lblTotalCount" runat="server">0</asp:Label>
        </td>
        <td>
            <asp:Label ID="lblTotalIncome" runat="server">0</asp:Label>
        </td>
        <td>
            <asp:Label ID="lblTotalRealIncome" runat="server">0</asp:Label>
        </td>
        <td>
            <asp:Label ID="lblTotalPayout" runat="server">0</asp:Label>
        </td>
        <td>
            <asp:Label ID="lblTotalRealPayout" runat="server">0</asp:Label>
        </td>
        <td>
            <asp:Label ID="lblGain" ForeColor="green" runat="server">0</asp:Label>
        </td>
        <td>
            <asp:Label ID="lblRealGain" ForeColor="green" runat="server">0</asp:Label>
        </td>
    </tr>
</table>
<h2>相关记录</h2>
<asp:GridView ID="BillsGridView" runat="server" AutoGenerateColumns="False" CssClass="normal mouseOver">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="Id" Target="_blank"
            DataNavigateUrlFormatString="~/BalanceTable.aspx?id={0}" Text="收支表" />
        <asp:HyperLinkField DataNavigateUrlFields="Id" Target="_blank" 
            DataNavigateUrlFormatString="~/Bill/Bill.aspx?id={0}"
             DataTextField="Number" HeaderText="清单编号" />
        <asp:TemplateField HeaderText="处理状态">
            <ItemTemplate>
                <span class="audit"><%# Formater.GetStateText((Active.Core.State.StateValue)Eval("StateValue"))%>
                </span>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="投放日期">
            <ItemTemplate>
                <asp:Label ID="lblRealIncome" runat="server" Text='<%# Eval("StartDate", "{0:yyyy-M-d}") +"~"+ Eval("EndDate", "{0:yyyy-M-d}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
        暂无清单信息
    </EmptyDataTemplate>
</asp:GridView>

<asp:GridView ID="OrderListGridView" runat="server" CssClass="normal mouseOver"
    AutoGenerateColumns="False">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="Id" Target="_blank"
            DataNavigateUrlFormatString="~/Bill/CustomerOrders.aspx?id={0}"
            Text="客户订单" />
        <asp:HyperLinkField DataNavigateUrlFields="Id" Target="_blank"
            DataNavigateUrlFormatString="~/Bill/MediaOrders.aspx?id={0}"
            Text="媒介订单" />
        <asp:TemplateField HeaderText="处理状态">
            <ItemTemplate>
                <span class="audit"><%# Formater.GetStateText((Active.Core.State.StateValue)Eval("StateValue"))%>
                </span>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="播放版本" SortExpression="PlayVersions">
            <ItemTemplate>
                <%# Formater.PlayVersions(((string)Eval("PlayVersions")).Split('|')) %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="广告周期">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("StartDate", "{0:yyyy-M-d}") +"~"+ Eval("EndDate", "{0:yyyy-M-d}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
        暂无订单信息.
    </EmptyDataTemplate>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
        <div class="loadingMessage">信息统计中, 请稍后.</div>
    </ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>

